﻿using System;
using System.IO;
//using System.Linq;

namespace FileShredder
{
    public enum TypeReplace { High, Middle, Simple }
    public class ShredderFile
    {
        private FileInfo _file;
        private byte[] _allFilesByte;
        public ShredderFile(FileInfo file)
        {
            if (!file.Exists)
                throw new FileNotFoundException("File not found!");
            _file = file;
            _allFilesByte = File.ReadAllBytes(file.FullName);
        }

        public void StepReplace(byte? byteReplace = null)
        {
            var replaseByte = byteReplace ?? (byte)new Random().Next(0, 255);
            for (int i = 0; i < _allFilesByte.Length; i++)
                _allFilesByte[i] = replaseByte;

            //_allBytes = _allBytes.Select(byteElem => byteElem = replaseByte).ToArray();

            using (var file = _file.Open(FileMode.Open, FileAccess.Write))
            {
                file.Write(_allFilesByte, 0, _allFilesByte.Length);
                file.Flush(true);
            }
        }
       
        public void ReplaceFile(params byte?[] bytesReplace)
        {
            foreach (var byteReplase in bytesReplace)
                StepReplace(byteReplase);
        }

        public void ReplaceFile(TypeReplace typeReplace)
        {
            switch (typeReplace)
            {
                case TypeReplace.High:
                    {
                        ReplaceFile(0xFF, 0x11, null, 0x00);
                        break;
                    }
                case TypeReplace.Middle:
                    {
                        ReplaceFile(0xFF, 0x00);
                        break;
                    }
                case TypeReplace.Simple:
                    {
                        ReplaceFile(new byte?[] { 0x00 });
                        break;
                    }
                default: throw new NotImplementedException("Type Replace not implemented!");
            }
        }

        public void DeleteFile()
        {
            _file.Delete();
        }
    }
}
